﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BFlatCompile.Nodes;

namespace BFlatCompile.Serializer
{
	internal static class Phase23CreatePrimitiveMethodLookup
	{
		public static string Do(Compiler compiler, Dictionary<string, Namespace> rootNamespaces)
		{
			Dictionary<string, int> methods = new Dictionary<string, int>();
			foreach (Class c in rootNamespaces["System"].Classes)
			{
				if (c.Name == "PrimitiveMethods")
				{
					foreach (Method method in c.Methods)
					{
						if (method.Name != null)
						{
							methods[method.Name] = method.ID;
						}
					}
					break;
				}
			}

			int[] methodIds = new int[] {
				methods["listAdd"], // 0
				methods["listClear"], // 1
				methods["mapGet"], // 2
				methods["mapContains"], // 3
				methods["listAddList"], // 4
				methods["listInsert"], // 5
				methods["listReverse"], // 6
				methods["mapAdd"], // 7
				methods["mapClear"], // 8
				methods["listJoin"], // 9
				methods["stringSplit"], // 10
				methods["stringTrim"], // 11
				methods["listRemove"], // 12
			};

			List<string> values = new List<string>();
			foreach (int methodId in methodIds)
			{
				values.Add(Util.ToHex(compiler, methodId));
			}

			return string.Join(Util.GetRowDelimiter(compiler), values);
		}
	}
}
